import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import Button, { ButtonSize, ButtonType, Shape } from "./Button";

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
  title: "components/Button",
  component: Button,
  parameters: {
    // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
    layout: "centered",
  },
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
  tags: ["autodocs"],
  // More on argTypes: https://storybook.js.org/docs/api/argtypes
  argTypes: {
    size: {
      control: "radio",
      options: Object.values(ButtonSize),
      description: "按钮大小",
    },
    btnType: {
      control: "radio",
      options: Object.values(ButtonType),
      description: "按钮类型",
    },
    disabled: { control: "boolean", description: "是否可用" },
    block: { control: "boolean", description: "是否占满一行" },
    href: { control: "text", description: "跳转链接" },
    ghost: { control: "boolean", description: "是否无背景" },
    shape: {
      control: "radio",
      options: Object.values(Shape),
      description: "按钮形状",
    },
  },
  // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
  args: { onClick: fn() },
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
  args: {
    children: "Default Button",
  },
};
export const DifferentSize: Story = {
  render: () => (
    <>
      <Button size={ButtonSize.Small}>Small Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button size={ButtonSize.Large}>Large Button</Button>
    </>
  ),
};

export const DifferentShape: Story = {
  render: () => (
    <>
      <Button shape={Shape.Circle}>Circle Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button shape={Shape.Default}>Default Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button shape={Shape.Round}>Round Button</Button>
    </>
  ),
};

export const DifferentType: Story = {
  render: () => (
    <>
      <Button btnType={ButtonType.Primary}>Primary Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button btnType={ButtonType.Danger}>Danger Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button btnType={ButtonType.Dashed}>Dashed Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button btnType={ButtonType.Default}>Default Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button btnType={ButtonType.Link}>Link Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button btnType={ButtonType.Primary}>Primary Button</Button>
      <div style={{ height: "20px" }}></div>
      <Button btnType={ButtonType.Text}>Text Button</Button>
    </>
  ),
};
